/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bsc.war.handler;

import bsc.ejb.entity.Attachment;
import bsc.ejb.entity.Note;
import bsc.ejb.entity.ScoreCard;
import bsc.war.delegate.DelegateBSC;
import bsc.war.factory.Factory;
import bsc.war.model.Score;
import bsc.war.service.ScoreCardUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 *
 * @author Miguel Angel
 */
public class DashboardNotes extends AbstractController {

    public DashboardNotes() {
    }

    @Override
    protected ModelAndView handleRequestInternal(
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        try {
            DelegateBSC delegate = (DelegateBSC) Factory.getBean("DelegateBSC");

            processRequestInternal(request, response, delegate);

        } catch (Exception e) {
            logger.error("Catched exception",e);
        }
        return new ModelAndView("dashboardNotes");
    }
    public static void processRequestInternal( HttpServletRequest request,
            HttpServletResponse response, DelegateBSC delegate){

            //Find the scorecards
            Long idScoreCard = Long.parseLong(request.getParameter("scoreCard"));
            ScoreCard scoreCard = delegate.findScoreCard(idScoreCard);

        
            Map <Note, List<Attachment>> noteAttachments = new HashMap<Note, List<Attachment>>();

          
            List<Note> notes = delegate.findNote(scoreCard);

            for (Note note : notes) {
                List<Attachment> attachments = delegate.findAttachment(note);
                noteAttachments.put(note, attachments);
            }

            request.setAttribute("scoreCard", scoreCard);       
            request.setAttribute("notes", notes);
            request.setAttribute("noteAttachments", noteAttachments);

    }
}